// 寻找列表中最接近制定数字的值，并返回
function find_close_num(arr, num) {
    let index = 0; 
    let d_value = Number.MAX_VALUE; 
    for (let i = 0; i < arr.length; i++) {
        let new_d_value = Math.abs(arr[i] - num); 
        if (new_d_value <= d_value) { 
            if (new_d_value === d_value && arr[i] < arr[index]) { 
                continue;
            }
            index = i;
            d_value = new_d_value;
        }
    }
    return arr[index];
}
// 返回数字位数
function sbit(num){ 
	let str = num.toString()
	if(str.indexOf('.')>-1){
		return str.split('.')[0].length
	}else{
		return str.length
	}
}
// 生成制定位数的整数 ，10 100 1000 10000==
function int_num_gen(num){
	let len = sbit(num);
	let pwd = "";
	for(let idx = 0; idx < len; idx ++){
		let seed = parseInt(idx==0?1:0);
		pwd = pwd + seed;
	}
	return pwd;
}
let step_list = [10,20,40,50,100,200,300,400,500,600,700,800,900,1000,2000,3000,4000,5000,6000,7000,8000,9000,10000,20000,30000,40000,50000,60000,70000,80000,90000,100000];
// 预置步长列表


// 获取输入的数组最大值，对应的图表MAX值和步长值
function step_max_getter(number){
	let max = 0;
	let big_step = int_num_gen(number); // big step 
	let raw = number/big_step;    	  //  raw ratio
	let big_step_num = Math.ceil(raw);  	  	  // big step number 多少个 步长
	if(sbit(number)<3){
		max = 100
	}else{
		max = big_step*big_step_num
	}
	// let ture_step = find_close_num(step_list,max/6)  // 寻找步长列表中最近的一个，表格总共6个刻度，可调
	if ((raw)%1 == 0 || number/max>0.9) {
		max+=parseInt(big_step)
	}
	// console.log('数组最大数字为:',number,'\t图表max值:',max,'\ \ttrue_step: '+ture_step)
	return max
}
export {
    step_max_getter
}